/* CacheIO - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
import java.awt.Graphics;

public class CacheIO {
	public Class18 indexFile = null;
	public Class18 dataFile = null;
	public int cacheIndex;
	public static Class19 aClass19_95;
	public static JString aClass3_96;
	public static int anInt97 = 0;
	public int maxFileSize = 65000;
	public static int anInt99;
	public static JString aClass3_100;

	public static boolean method122(Signlink class21, int i, boolean bool) {
		Class39_Sub9.anInt1415 = 20;
		try {
			Class55.aClass62_1251 = (Class62) Class.forName("Class62_Sub1_Sub1").newInstance();
			return true;
		} catch (Throwable throwable) {
			Runnable_Impl1 runnable_impl1 = class21.method251(i ^ i);
			if (runnable_impl1 != null) {
				Class55.aClass62_1251 = new Class62_Sub1_Sub2(class21, runnable_impl1);
				return true;
			}
			return false;
		}
	}

	public static void method123(RSInterface inter, int i) {
		int i_0_ = inter.anInt2078;
		if (i_0_ >= 1 && i_0_ <= 100 || i_0_ >= 701 && i_0_ <= 800) {
			if (Class14.anInt232 == 0) {
				if (i_0_ == 1) {
					inter.text = Class15.aClass3_286;
					inter.anInt2089 = 0;
					return;
				}
				if (i_0_ == 2) {
					inter.text = Class39_Sub5_Sub4_Sub2.aClass3_2230;
					inter.anInt2089 = 0;
					return;
				}
			}
			if (Class14.anInt232 == 1) {
				if (i_0_ == 1) {
					inter.text = Class39_Sub5.aClass3_1346;
					inter.anInt2089 = 0;
					return;
				}
				if (i_0_ == 2) {
					inter.text = Class39_Sub5_Sub4_Sub2.aClass3_2222;
					inter.anInt2089 = 0;
					return;
				}
				if (i_0_ == 3) {
					inter.text = Class14.aClass3_256;
					inter.anInt2089 = 0;
					return;
				}
			}
			if (i_0_ > 700)
				i_0_ -= 601;
			else
				i_0_--;
			int i_1_ = Class4.anInt62;
			if (Class14.anInt232 != 2)
				i_1_ = 0;
			if (i_1_ <= i_0_) {
				inter.anInt2089 = 0;
				inter.text = Class66.aClass3_1164;
			} else {
				inter.text = Class39_Sub5_Sub4_Sub1.aClass3Array2188[i_0_];
				inter.anInt2089 = 1;
			}
		} else if (i_0_ >= 101 && i_0_ <= 200 || i_0_ >= 801 && i_0_ <= 900) {
			if (i_0_ > 800)
				i_0_ -= 701;
			else
				i_0_ -= 101;
			int i_2_ = Class4.anInt62;
			if (Class14.anInt232 != 2)
				i_2_ = 0;
			if (i_0_ >= i_2_) {
				inter.text = Class66.aClass3_1164;
				inter.anInt2089 = 0;
			} else {
				if (Player.anIntArray2533[i_0_] == 0)
					inter.text = Class39_Sub5_Sub11.method708((new JString[] { (Class39_Sub10.aClass3_1421), (Class45.aClass3_864) }), 14569);
				else if (Player.anIntArray2533[i_0_] >= 5000) {
					if (Player.anIntArray2533[i_0_] != Class18.anInt344)
						inter.text = (Class39_Sub5_Sub11.method708((new JString[] { Class19.aClass3_368, Class44.aClass3_847, (Class57.method1007((byte) 71, (Player.anIntArray2533[i_0_]) - 5000)) }), 14569));
					else
						inter.text = (Class39_Sub5_Sub11.method708((new JString[] { Class41.aClass3_783, Class44.aClass3_847, (Class57.method1007((byte) 71, (Player.anIntArray2533[i_0_]) - 5000)) }), 14569));
				} else if (Player.anIntArray2533[i_0_] != Class18.anInt344)
					inter.text = (Class39_Sub5_Sub11.method708((new JString[] { Class19.aClass3_368, Class39_Sub11.aClass3_1465, Class57.method1007((byte) 71, (Player.anIntArray2533[i_0_])) }), 14569));
				else
					inter.text = (Class39_Sub5_Sub11.method708((new JString[] { Class41.aClass3_783, Class39_Sub11.aClass3_1465, Class57.method1007((byte) 71, (Player.anIntArray2533[i_0_])) }), 14569));
				inter.anInt2089 = 1;
			}
		} else if (i_0_ == 203) {
			int i_3_ = Class4.anInt62;
			if (Class14.anInt232 != 2)
				i_3_ = 0;
			inter.anInt2095 = i_3_ * 15 + 20;
			if (inter.anInt2015 >= inter.anInt2095)
				inter.anInt2095 = inter.anInt2015 + 1;
		} else if (i_0_ >= 401 && i_0_ <= 500) {
			i_0_ -= 401;
			if (i_0_ == 0 && Class14.anInt232 == 0) {
				inter.anInt2089 = 0;
				inter.text = Class39_Sub5_Sub4_Sub5.aClass3_2353;
			} else if (i_0_ == 1 && Class14.anInt232 == 0) {
				inter.text = Class39_Sub5_Sub4_Sub2.aClass3_2230;
				inter.anInt2089 = 0;
			} else {
				int i_4_ = Class15.anInt282;
				if (Class14.anInt232 == 0)
					i_4_ = 0;
				if (i_4_ <= i_0_) {
					inter.text = Class66.aClass3_1164;
					inter.anInt2089 = 0;
				} else {
					inter.text = Deque.longToString(Class39_Sub5_Sub9.aLongArray1808[i_0_], (byte) 83).capitalizeAfterQuestion((byte) -85);
					inter.anInt2089 = 1;
				}
			}
		} else if (i_0_ == 503) {
			inter.anInt2095 = Class15.anInt282 * 15 + 20;
			if (inter.anInt2015 >= inter.anInt2095)
				inter.anInt2095 = inter.anInt2015 + 1;
		} else if (i_0_ == 324) {
			if (CacheArchive.anInt1287 == -1) {
				Class23.anInt436 = inter.anInt2034;
				CacheArchive.anInt1287 = inter.anInt2093;
			}
			if (!Class39_Sub5_Sub2.aClass45_1705.aBoolean854)
				inter.anInt2093 = Class23.anInt436;
			else
				inter.anInt2093 = CacheArchive.anInt1287;
		} else if (i_0_ == 325) {
			if (CacheArchive.anInt1287 == -1) {
				Class23.anInt436 = inter.anInt2034;
				CacheArchive.anInt1287 = inter.anInt2093;
			}
			if (Class39_Sub5_Sub2.aClass45_1705.aBoolean854)
				inter.anInt2093 = Class23.anInt436;
			else
				inter.anInt2093 = CacheArchive.anInt1287;
		} else if (i_0_ == 327) {
			inter.anInt2098 = 150;
			inter.anInt2011 = ((int) (Math.sin((double) Class2.anInt48 / 40.0) * 256.0) & 0x7ff);
			inter.anInt2009 = 5;
			inter.anInt2026 = 0;
		} else if (i_0_ == 328) {
			inter.anInt2098 = 150;
			inter.anInt2011 = ((int) (Math.sin((double) Class2.anInt48 / 40.0) * 256.0) & 0x7ff);
			inter.anInt2009 = 5;
			inter.anInt2026 = 1;
		} else {
			if (i_0_ == 600)
				inter.text = Class39_Sub5_Sub11.method708((new JString[] { Class66.aClass3_1163, Class4.aClass3_73 }), 14569);
			else if (i_0_ == 620) {
				if (anInt97 >= 1) {
					if (Class39_Sub12.aBoolean1487) {
						inter.text = Class40.aClass3_751;
						inter.anInt2077 = 16711680;
					} else {
						inter.text = Class10.aClass3_173;
						inter.anInt2077 = 16777215;
					}
				} else
					inter.text = Class66.aClass3_1164;
			}
		}
	}

	public boolean writeFile(int i, byte[] bytes, int fileId, int len) {
		synchronized (dataFile) {
			if (len < i || maxFileSize < len)
				throw new IllegalArgumentException();
			boolean bool = writeFile((byte) -122, fileId, true, len, bytes);
			if (!bool)
				bool = writeFile((byte) -70, fileId, false, len, bytes);
			return bool;
		}
	}

	public boolean writeFile(byte i, int fileId, boolean exists, int fileSize, byte[] is) {
		synchronized (dataFile) {
			try {
				if (i >= -37)
					aClass3_100 = null;
				int blockIndex;
				if (!exists) {
					blockIndex = (int) ((dataFile.length() + 519L) / 520L);
					if (blockIndex == 0)
						blockIndex = 1;
				} else {
					if (indexFile.length() < (long) (fileId * 6 + 6))
						return false;
					indexFile.seek(0, (long) (fileId * 6));
					indexFile.read(Class19.cacheFileBuffer, 6, -13443, 0);
					blockIndex = ((Class19.cacheFileBuffer[3] << 16 & 0xff0000) + ((Class19.cacheFileBuffer[4] & 0xff) << 8) + (Class19.cacheFileBuffer[5] & 0xff));
					if (blockIndex <= 0 || (long) blockIndex > dataFile.length() / 520L)
						return false;
				}
				Class19.cacheFileBuffer[5] = (byte) blockIndex;
				Class19.cacheFileBuffer[4] = (byte) (blockIndex >> 8);
				Class19.cacheFileBuffer[0] = (byte) (fileSize >> 16);
				int i_11_ = 0;
				Class19.cacheFileBuffer[1] = (byte) (fileSize >> 8);
				Class19.cacheFileBuffer[2] = (byte) fileSize;
				Class19.cacheFileBuffer[3] = (byte) (blockIndex >> 16);
				indexFile.seek(0, (long) (fileId * 6));
				indexFile.write(6, 0, -23910, Class19.cacheFileBuffer);
				int i_12_ = 0;
				int i_13_;
				for (/**/; fileSize > i_11_; i_11_ += i_13_) {
					int i_14_ = 0;
					if (exists) {
						dataFile.seek(0, (long) (blockIndex * 520));
						try {
							dataFile.read(Class19.cacheFileBuffer, 8, -13443, 0);
						} catch (java.io.EOFException eofexception) {
							break;
						}
						i_14_ = ((Class19.cacheFileBuffer[6] & 0xff) + ((Class19.cacheFileBuffer[5] << 8 & 0xff00) + (Class19.cacheFileBuffer[4] << 16 & 0xff0000)));
						i_13_ = ((Class19.cacheFileBuffer[0] << 8 & 0xff00) + (Class19.cacheFileBuffer[1] & 0xff));
						int i_15_ = Class19.cacheFileBuffer[7] & 0xff;
						int i_16_ = (((Class19.cacheFileBuffer[2] & 0xff) << 8) + (Class19.cacheFileBuffer[3] & 0xff));
						if (i_13_ != fileId || i_16_ != i_12_ || cacheIndex != i_15_)
							return false;
						if (i_14_ < 0 || ((long) i_14_ > dataFile.length() / 520L))
							return false;
					}
					if (i_14_ == 0) {
						exists = false;
						i_14_ = (int) ((dataFile.length() + 519L) / 520L);
						if (i_14_ == 0)
							i_14_++;
						if (blockIndex == i_14_)
							i_14_++;
					}
					Class19.cacheFileBuffer[3] = (byte) i_12_;
					i_13_ = -i_11_ + fileSize;
					Class19.cacheFileBuffer[2] = (byte) (i_12_ >> 8);
					if (fileSize - i_11_ <= 512)
						i_14_ = 0;
					Class19.cacheFileBuffer[6] = (byte) i_14_;
					Class19.cacheFileBuffer[4] = (byte) (i_14_ >> 16);
					i_12_++;
					Class19.cacheFileBuffer[5] = (byte) (i_14_ >> 8);
					Class19.cacheFileBuffer[7] = (byte) cacheIndex;
					if (i_13_ > 512)
						i_13_ = 512;
					Class19.cacheFileBuffer[0] = (byte) (fileId >> 8);
					Class19.cacheFileBuffer[1] = (byte) fileId;
					dataFile.seek(0, (long) (blockIndex * 520));
					blockIndex = i_14_;
					dataFile.write(8, 0, -23910, Class19.cacheFileBuffer);
					dataFile.write(i_13_, i_11_, -23910, is);
				}
				return true;
			} catch (java.io.IOException ioexception) {
				return false;
			}
		}
	}

	public byte[] readFile(int i, int fileId) {
		synchronized (dataFile) {
			try {
				if (indexFile.length() < (long) (fileId * 6 + 6))
					return null;
				indexFile.seek(0, (long) (fileId * 6));
				indexFile.read(Class19.cacheFileBuffer, 6, -13443, 0);
				int fileSize = ((Class19.cacheFileBuffer[2] & 0xff) + (((Class19.cacheFileBuffer[1] & 0xff) << 8) + (Class19.cacheFileBuffer[0] << 16 & 0xff0000)));
				int blockIndex = ((Class19.cacheFileBuffer[5] & 0xff) + ((Class19.cacheFileBuffer[4] << 8 & 0xff00) + ((Class19.cacheFileBuffer[3] & 0xff) << 16)));
				if (fileSize < 0 || fileSize > maxFileSize)
					return null;
				if (blockIndex <= 0 || (long) blockIndex > dataFile.length() / 520L)
					return null;
				int filePart = 0;
				int totalReadSize = 0;
				byte[] is = new byte[fileSize];
				while (totalReadSize < fileSize) {
					if (blockIndex == 0)
						return null;
					int dataRemaining = fileSize - totalReadSize;
					dataFile.seek(0, (long) (blockIndex * 520));
					if (dataRemaining > 512)
						dataRemaining = 512;
					dataFile.read(Class19.cacheFileBuffer, dataRemaining + 8, -13443, 0);
					int nextBlock = ((Class19.cacheFileBuffer[6] & 0xff) + ((Class19.cacheFileBuffer[4] & 0xff) << 16) + ((Class19.cacheFileBuffer[5] & 0xff) << 8));
					int thisCacheIndex = Class19.cacheFileBuffer[7] & 0xff;
					int thisFilePart = ((Class19.cacheFileBuffer[3] & 0xff) + ((Class19.cacheFileBuffer[2] & 0xff) << 8));
					int blockFileId = ((Class19.cacheFileBuffer[1] & 0xff) + (Class19.cacheFileBuffer[0] << 8 & 0xff00));
					if (blockFileId != fileId || filePart != thisFilePart || cacheIndex != thisCacheIndex)
						return null;
					if (nextBlock < 0 || dataFile.length() / 520L < (long) nextBlock)
						return null;
					for (int i_27_ = 0; dataRemaining > i_27_; i_27_++)
						is[totalReadSize++] = Class19.cacheFileBuffer[i_27_ + 8];
					filePart++;
					blockIndex = nextBlock;
				}
				return is;
			} catch (java.io.IOException ioexception) {
				return null;
			}
		}
	}

	public String toString() {
		return "Cache:" + cacheIndex;
	}

	public static void method127(int i) {
		try {
			Graphics graphics = Class41.aCanvas778.getGraphics();
			CollisionMap.aClass57_514.method1010(-51, graphics, i, 357);
		} catch (Exception exception) {
			Class41.aCanvas778.repaint();
		}
	}

	public static void method128(byte i) {
		if (Class20.anInt397 > 0) {
			for (int i_28_ = 0; i_28_ < 256; i_28_++) {
				if (Class20.anInt397 > 768)
					Class39_Sub5_Sub4_Sub3.anIntArray2245[i_28_] = Class57_Sub2.method1011(Class18.anIntArray338[i_28_], -Class20.anInt397 + 1024, Class23.anIntArray423[i_28_], (byte) -27);
				else if (Class20.anInt397 > 256)
					Class39_Sub5_Sub4_Sub3.anIntArray2245[i_28_] = Class23.anIntArray423[i_28_];
				else
					Class39_Sub5_Sub4_Sub3.anIntArray2245[i_28_] = Class57_Sub2.method1011(Class23.anIntArray423[i_28_], -Class20.anInt397 + 256, Class18.anIntArray338[i_28_], (byte) 122);
			}
		} else if (Canvas_Sub1.anInt24 <= 0) {
			for (int i_29_ = 0; i_29_ < 256; i_29_++)
				Class39_Sub5_Sub4_Sub3.anIntArray2245[i_29_] = Class18.anIntArray338[i_29_];
		} else {
			for (int i_30_ = 0; i_30_ < 256; i_30_++) {
				if (Canvas_Sub1.anInt24 <= 768) {
					if (Canvas_Sub1.anInt24 > 256)
						Class39_Sub5_Sub4_Sub3.anIntArray2245[i_30_] = Class39_Sub5_Sub4_Sub3.anIntArray2247[i_30_];
					else
						Class39_Sub5_Sub4_Sub3.anIntArray2245[i_30_] = (Class57_Sub2.method1011(Class39_Sub5_Sub4_Sub3.anIntArray2247[i_30_], -Canvas_Sub1.anInt24 + 256, Class18.anIntArray338[i_30_], (byte) -100));
				} else
					Class39_Sub5_Sub4_Sub3.anIntArray2245[i_30_] = Class57_Sub2.method1011(Class18.anIntArray338[i_30_], -Canvas_Sub1.anInt24 + 1024, (Class39_Sub5_Sub4_Sub3.anIntArray2247[i_30_]), (byte) -64);
			}
		}
		int i_31_ = 256;
		for (int i_32_ = 0; i_32_ < 33920; i_32_++)
			Class31.aClass57_551.anIntArray998[i_32_] = Deque.aClass39_Sub5_Sub10_Sub3_920.anIntArray2476[i_32_];
		int i_33_ = 0;
		int i_34_ = 1152;
		for (int i_35_ = 1; i_35_ < i_31_ - 1; i_35_++) {
			int i_36_ = (-i_35_ + i_31_) * Class40.anIntArray762[i_35_] / i_31_;
			int i_37_ = 22 + i_36_;
			if (i_37_ < 0)
				i_37_ = 0;
			i_33_ += i_37_;
			for (int i_38_ = i_37_; i_38_ < 128; i_38_++) {
				int i_39_ = OnDemandFetcher.anIntArray1202[i_33_++];
				if (i_39_ != 0) {
					int i_40_ = i_39_;
					int i_41_ = Class31.aClass57_551.anIntArray998[i_34_];
					int i_42_ = -i_39_ + 256;
					i_39_ = Class39_Sub5_Sub4_Sub3.anIntArray2245[i_39_];
					Class31.aClass57_551.anIntArray998[i_34_++] = (Class34.method342((i_40_ * Class34.method342(i_39_, 65280) + (i_42_ * Class34.method342(65280, i_41_))), 16711680) + (Class34.method342(-16711936, (i_40_ * Class34.method342(16711935, i_39_) + i_42_ * Class34.method342(i_41_, 16711935))))) >> 8;
				} else
					i_34_++;
			}
			i_34_ += i_37_;
		}
		int i_43_ = -58 % ((-21 - i) / 52);
		i_33_ = 0;
		for (int i_44_ = 0; i_44_ < 33920; i_44_++)
			Class68.aClass57_1186.anIntArray998[i_44_] = ISAAC.aClass39_Sub5_Sub10_Sub3_1096.anIntArray2476[i_44_];
		i_34_ = 1176;
		for (int i_45_ = 1; i_45_ < i_31_ - 1; i_45_++) {
			int i_46_ = (-i_45_ + i_31_) * Class40.anIntArray762[i_45_] / i_31_;
			int i_47_ = -i_46_ + 103;
			i_34_ += i_46_;
			for (int i_48_ = 0; i_48_ < i_47_; i_48_++) {
				int i_49_ = OnDemandFetcher.anIntArray1202[i_33_++];
				if (i_49_ != 0) {
					int i_50_ = i_49_;
					int i_51_ = 256 - i_49_;
					i_49_ = Class39_Sub5_Sub4_Sub3.anIntArray2245[i_49_];
					int i_52_ = Class68.aClass57_1186.anIntArray998[i_34_];
					Class68.aClass57_1186.anIntArray998[i_34_++] = ((Class34.method342(-16711936, ((Class34.method342(i_49_, 16711935) * i_50_) + (i_51_ * Class34.method342(16711935, i_52_)))) + (Class34.method342(16711680, (i_51_ * Class34.method342(i_52_, 65280) + i_50_ * Class34.method342(65280, i_49_))))) >> 8);
				} else
					i_34_++;
			}
			i_34_ += -i_47_ + 128 - i_46_;
			i_33_ += 128 - i_47_;
		}
	}

	public static void method129(boolean bool) {
		aClass3_100 = null;
		aClass19_95 = null;
		aClass3_96 = null;
	}

	public CacheIO(int index, Class18 class18, Class18 class18_53_, int i_54_) {
		indexFile = class18_53_;
		maxFileSize = i_54_;
		cacheIndex = index;
		dataFile = class18;
	}

	static {
		aClass3_96 = Class39_Sub5_Sub9.createJString(122, "Empf-=nger:");
		anInt99 = 0;
		aClass19_95 = new Class19(32);
		aClass3_100 = (Class39_Sub5_Sub9.createJString(122, "Um ein neues Spielkonto zu erstellen)1 m-Ussen Sie"));
	}
}
